/**  
 * All rights Reserved, Designed By www.tydic.com
 * @Title:  MessageServiceImpl.java   
 * @Package com.axin.service.impl   
 * @Description:    TODO(用一句话描述该文件做什么)   
 * @author: axin     
 * @date:   2019年3月23日 下午10:46:56   
 * @version V1.0 
 * @Copyright: 2019 www.hao456.top Inc. All rights reserved. 
 */
package com.axin.service.impl;

import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.axin.common.entity.SocketResult;
import com.axin.common.websocket.WebSocketServer;
import com.axin.service.MessageService;

/**   
 * @Description: TODO 
 * @ClassName:  MessageServiceImpl
 * @author:  Axin 
 * @date:   2019年3月23日 下午10:46:56   
 * @Copyright: 2019 www.hao456.top Inc. All rights reserved. 
 */
@Service
public class MessageServiceImpl implements MessageService {

	
	private Logger logger = LoggerFactory.getLogger(MessageServiceImpl.class);
   
	
	
	@Autowired
    private WebSocketServer webSocketServer;
    
    
	/* (non-Javadoc)
	 * @see com.axin.service.MessageService#sendMessage(java.lang.Long, java.lang.String)
	 */
	@Override
	public Boolean sendConsoleMessage(Long userId, String message) {
		logger.info("向用户{}发送消息：{}",userId,message);
		message = time() + " - " + message;
		SocketResult result = new SocketResult(SocketResult.CONSOLE,message);
        if(webSocketServer.sendMessageToUser(userId+"",result)){
            return true;
        }else{
            return false;
        }   
	}


	@Override
	public Boolean sendTaskUpdateNotify(Long userId) {
		logger.info("通知用户{}更新任务列表：",userId);
		SocketResult result = new SocketResult(SocketResult.TASK_UPDATE,null);
        if(webSocketServer.sendMessageToUser(userId+"",result)){
            return true;
        }else{
            return false;
        }   
	}
	
	 private String time(){
			String dateTime = new DateTime().toString("yyyy-MM-dd HH:mm:ss.SSS");
			return dateTime;
	  }


	/* (non-Javadoc)
	 * @see com.axin.service.MessageService#sendBuyTradesUpdateNotify(java.lang.Long)
	 */
	@Override
	public Boolean sendBuyTradesUpdateNotify(Long userId) {
		logger.info("通知用户{}更新购买交易列表：",userId);
		SocketResult result = new SocketResult(SocketResult.BUY_TRADES_UPDATE,null);
        if(webSocketServer.sendMessageToUser(userId+"",result)){
            return true;
        }else{
            return false;
        }  
	}


	/* (non-Javadoc)
	 * @see com.axin.service.MessageService#sendSellTradesUpdateNotify(java.lang.Long)
	 */
	@Override
	public Boolean sendSellTradesUpdateNotify(Long userId) {
		logger.info("通知用户{}更新销售交易列表：",userId);
		SocketResult result = new SocketResult(SocketResult.SELL_TRADES_UPDATE,null);
        if(webSocketServer.sendMessageToUser(userId+"",result)){
            return true;
        }else{
            return false;
        } 
	}
	 
	 
	 
	

}
